﻿@using Himall.Core;
@model Himall.Model.OrderInfo


<div class="container">
    <ul class="nav nav-tabs-custom clearfix">
        <strong>订单</strong>
        <li class="active"><a>查看 </a></li>
    </ul>

    <h3 class="table-hd">商品清单</h3>
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>商品名称</th>
                <th>规格</th>
                <th>数量</th>
                <th>单价</th>
                <th>改价</th>
                <th>总价</th>
                <th>佣金</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var orderItem in Model.OrderItemInfo)
            {
                <tr>
                    <td>
                        <a target="_blank" href="/product/detail/@orderItem.ProductId">
                            <img style="margin-left:15px;" width="40" height="40" src="@orderItem.ThumbnailsUrl">@orderItem.ProductName
                        </a>
                    </td>
                    <td>@orderItem.Color @orderItem.Size @orderItem.Version</td>
                    <td>@orderItem.Quantity</td>
                    <td class="ftx-04">@orderItem.SalePrice.ToString("F2")</td>
                    <td class="ftx-04">
                        @if (@orderItem.DiscountAmount > 0)
                        {
                            <span>减: @orderItem.DiscountAmount.ToString("F2")</span>
                        }
                        else
                        {
                            <span>增: @Math.Abs(orderItem.DiscountAmount).ToString("F2")</span>
                        }
                    </td>
                    <td class="ftx-04">@orderItem.RealTotalPrice.ToString("F2")</td>

                    <td class="ftx-04">@((orderItem.CommisRate * (orderItem.RealTotalPrice - orderItem.RefundPrice)).ToString("F2"))</td>
                </tr>
            }
            <tr>
                <td align="right" colspan="7">
                    商品总价：￥ @Model.ProductTotalAmount.ToString("F2")&nbsp;&nbsp;&nbsp;
                    &nbsp; &nbsp; &nbsp;运费：￥@Model.Freight.ToString("F2")
                    @if (@Model.DiscountAmount > 0)
                    {
                        <label> 优惠券抵扣金额:￥@Model.DiscountAmount.ToString("F2");</label>
                    }

                    @if (Model.IntegralDiscount > 0)
                    {
                        <label> 积分抵扣金额:￥@Model.IntegralDiscount.ToString("F2");</label>
                    }
                    <b>&nbsp;&nbsp;&nbsp;实付金额：￥@Model.OrderTotalAmount.ToString("F2")</b>
                </td>
            </tr>
        </tbody>
    </table>


    <h3 class="table-hd">订单信息</h3>
    <div class="order-info">
        <div class="caption">
            <p>订 单 号：@Model.Id</p>
            <p>订单状态：@Model.OrderStatus.ToDescription()</p>
            <p>下单会员：@Model.UserName</p>
        </div>
        <div class="caption">
            <p>收 货 人：@Model.ShipTo</p>
            <p>地    址：@Model.RegionFullName @Model.Address</p>
            <p>手机号码：@Model.CellPhone</p>
            @*<p>买家备注：@Model.UserRemark</p>*@
        </div>
        <div class="caption">
            @if (Model.PayDate != null && Model.OrderStatus != Himall.Model.OrderInfo.OrderOperateStatus.WaitPay)
            {
                if (@Model.OrderTotalAmount == 0)
                {
                    <p>支付方式： <span>积分支付</span></p>
                }
                else if (string.IsNullOrEmpty(Model.PaymentTypeName))
                {
                    <p>支付方式：平台确认收款  【备注：@{@Model.PayRemark}】</p>
                }
                else
                {

                    <p>支付方式：  @Model.PaymentTypeName @Model.PayRemark</p>
                }
            }
            @if( !string.IsNullOrEmpty( Model.ExpressCompanyName ) )
            {
                <p>物流公司：@Model.ExpressCompanyName</p>
            }
            @if( !string.IsNullOrEmpty( Model.ShipOrderNumber ) )
            {
                <p>快递单号：@Model.ShipOrderNumber</p>
            }
        </div>
        @if( Model.InvoiceType != Himall.Model.InvoiceType.None )
        {
            <div class="caption">
                <p>发票抬头：@Model.InvoiceTitle</p>
                <p>发票内容：@Model.InvoiceContext</p>
            </div>
        }
        else
        {
            <div class="caption">
                <p>不需要开发票</p>
            </div>
        }
    </div>

    <h3 class="table-hd">物流跟踪</h3>
    <table class="table table-bordered" id="tbExpressData"></table>

    <h3 class="table-hd">操作历史</h3>
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>操作者</th>
                <th>时间</th>
                <th>描述</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var orderOperationLog in Model.OrderOperationLogInfo)
            {
                <tr>
                    <td>@orderOperationLog.Operator</td>
                    <td>@orderOperationLog.OperateDate</td>
                    <td>@orderOperationLog.OperateContent</td>
                </tr>
            }
        </tbody>
    </table>

</div>
<script type="text/javascript">
    $(function () {
        $.post('../GetExpressData', { expressCompanyName: "@Model.ExpressCompanyName", shipOrderNumber: "@Model.ShipOrderNumber" }, function (result) {
            var html;
            var obj = jQuery.parseJSON(result);
            if (obj.message == "ok") {
                var data = obj.data;
                for (var i = 0; i < data.length; i++) {
                    html += '<tr><td>' + data[i].time + '</td>\
                             <td>' + data[i].context + '</td>';
                    html += '</tr>';
                }
            }

            else {
                html += '<tr><td>该单号暂无物流进展，请稍后再试，或检查公司和单号是否有误。</td></tr>';
            }

            html += '<tr><td><a href="http://www.kuaidi100.com" target="_blank" id="power" runat="server" style="color:Red;">此物流信息由快递100提供</a></td></tr>';

            $("#tbExpressData").html(html);
        });
    });
</script>